package com.ymatou.iapi.csim.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.csim.parameter.AssignBuyerUserBean;
import com.ymatou.iapi.csim.parameter.AssignSellerUserBean;
import com.ymatou.iapi.csim.parameter.SendMessageBean;
import com.ymatou.iapi.csim.service.AssignBuyerUserCall;
import com.ymatou.iapi.csim.service.AssignSellerUserCall;
import com.ymatou.iapi.csim.service.SendMessageCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CsimCallService;
import com.ymttest.database.model.ymt_onlinecs;
import com.ymttest.database.sqlwapper.CSIM.ymt_cssessionWapper;
import com.ymttest.database.sqlwapper.CSIM.ymt_onlinecsWapper;
import com.ymttest.database.sqlwapper.CSIM.ymt_queuesessionWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.MapUtil;
import com.ymttest.utils.TestDataManager;
/**
*买手用户分配客服(JOB)
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_AssignSellerUser{
	private static AssignSellerUserCall call;
	private CsimCallService csService=new CsimCallService();
	//private static AssignBuyerUserCall assignbuyeruserCall;
	private Integer userId=Integer.parseInt(EnvSetup.getData("userId_IM").toString());
	private Integer sellerId1=Integer.parseInt(EnvSetup.getData("autotest_seller1").toString());
	private ymt_queuesessionWapper queuesessionWapper=new ymt_queuesessionWapper();
	private ymt_onlinecsWapper onlinecsWapper=new ymt_onlinecsWapper();
	private ymt_cssessionWapper cssessionWapper=new ymt_cssessionWapper();
	private Integer csId=Integer.parseInt(TestDataManager.getRandomNum(5));
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("买手用户分配客服(JOB)");
	}

	@Before
	public void caseUp() {
		call=new AssignSellerUserCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AssignSellerUser_1() {
		Logger.start(true,"买手用户客服分配(JOB),验证有在线客服");
		try {
			userId=sellerId1;
			//删除当前用户旧会话
			cssessionWapper.deleteByUserId(MapUtil.hashMap("userId",userId));
			ymt_onlinecs onlinecs_old=csService.getOnlineCS_Seller(csId);
			//买家发消息
			SendMessageBean sendMessageBean=csService.setSendMessageBean();
			sendMessageBean.setUserId(userId);
			SendMessageCall sendMessageCall=csService.setSendMessageCall(sendMessageBean);
			
			call.callService();		
			Thread.sleep(5000);
			
			Logger.verifyEquals("ok", call.getReturnData(), "验证返回ok");
			//验证数据库
			//ymt_queuesession -1
			int count2=queuesessionWapper.selectBy_Count(MapUtil.hashMap("userId",sendMessageBean.getUserId()));
			Logger.verifyEquals(0, count2, "验证ymt_queuesession没有数据");
			//ymt_onlinecs currentSession+1
			ymt_onlinecs ymt_onlinecs=onlinecsWapper.selectBy(MapUtil.hashMap("CSId",csId)).get(0);
			Logger.verifyEquals(1, ymt_onlinecs.getCurrentSessions()-onlinecs_old.getCurrentSessions(), "验证数据库ymt_onlinecs表字段 currentSession加1");
			//ymt_cssession有数据 
			int count=cssessionWapper.selectBy_Count(MapUtil.hashMap("CSId",csId,"userId",sendMessageBean.getUserId(),"Status",0));
			Logger.verifyEquals(1, count, "验证数据库ymt_cssession表有当前会话数据");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}